package com.maple.soa.thread;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

/**
 * 多线程，图片下载
 * https://dss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1-66368c33f8.png
 *
 * @author lijian
 * @date 2021/4/24 22:38
 */
public class T02_Downloader {

    public static void main(String[] args) {
        System.out.println("==主线程开始==");
        String url = "https://dss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1-66368c33f8.png";
        for (int i = 1; i <= 3; i++) {
            int ti = i;
            new Thread(() -> {
                downImg(url, ti + ".png");
            }).start();
        }
        System.out.println("==主线程结束==");
    }

    public static void downImg(String url, String fileName) {
        try {
            FileUtils.copyURLToFile(new URL(url), new File(fileName));
            System.out.println("下载文件名称=>" + fileName);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}